package com.gudy.counter;

import com.gudy.counter.config.CounterConfig;
import com.gudy.counter.thirdpaet.uuid.GudyUuid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.context.annotation.Bean;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.server.standard.ServerEndpointExporter;

import javax.annotation.PostConstruct;

@SpringBootApplication
@EnableTransactionManagement
@EnableWebSocket
@ServletComponentScan
public class CounterApplication {

    @Autowired
    private  CounterConfig counterConfig;
    @PostConstruct
    private void init (){
        GudyUuid.getInstance().init(counterConfig.getDataCenterId(),counterConfig.getWorkerId());
    }
    public static void main(String[] args) {
        SpringApplication.run(CounterApplication.class, args);
    }
    @Bean
    public ServerEndpointExporter serverEndpointExporter() {
        return new ServerEndpointExporter();
    }
}
